# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
# 利用csvitemexporter把数据写入csv文件
from scrapy.exporters import CsvItemExporter
class BlblPipeline(object):
    def __init__(self):
        self.fp=open('bilibili.csv','ab') # a为追加写入，b表示用二进制方式打开文件
        self.exportre=CsvItemExporter(
            self.fp,
            include_headers_line=True,
            encoding='utf-8-sig'
        )
    def open_spider(self,spider):
        pass
    # 向csv文件写入数据
    def process_item(self, item, spider):
        self.exportre.export_item(item)
        return item
    def close_spider(self,spider):
        self.fp.close()
